<?php
//后台登陆控制
include_once('admin_global.php');
$db->Get_user_shell_check($uid, $shell);   //检测用户是否登录
$db->Get_user_type_check($uid, $shell);    //检测用户权限
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加友情链接</title>
    <link rel="stylesheet" href="css/right.css" type="text/css" />
</head>
<script>
    window.onload=function(){
        var myform=document.getElementById("form1");
        myform.onsubmit=check_addLink;
        function check_addLink(){
            if(myform.linkName.value==""){
                alert("请填写链接名称！");
                myform.linkName.focus();
                return false;
            }
            if(myform.linkUrl.value==""){
                alert("请填写链接地址！");
                myform.linkUrl.focus();
                return false;
            }
            if(myform.linkIndex.value==""){
                alert("请填写排列顺序！");
                myform.linkIndex.focus();
                return false;
            }
        }
    }
</script>
<?php
if (isset($_POST['addLinks'])) {
    $linkName = trim($_POST['linkName']);
    if (!empty($_POST['linkName'])) {
        $linkUrl = $_POST['linkUrl'];
        $linkIndex =intval( $_POST['linkIndex']);
        if (!empty($_POST['isEnabled'])) {
            $isEnabled = 1;
        } else {
            $isEnabled = 0;
        }
        $sql="INSERT INTO links(linkID,linkName,linkUrl,isEnabled,linkIndex) VALUES(null,'$linkName','$linkUrl',$isEnabled,$linkIndex)";
        $query=$db->query($sql);
        if($query==true){
            echo "<script>alert('链接添加成功！');location.href='listLinks.php';</script>";
        }else{
            echo "<script>alert('链接添加失败！');history.go(-1);</script>";
        }
    }else{
        echo "<script>alert('链接名称不能为空！');history.go(-1);</script>";
    }
}
?>
<body>
<div id="right_main">
    <div class="right_content">
        <div class="right_top_menu">
            <h3>
                您当前的位置：后台 > 基本设置 > 添加友情链接
            </h3>
        </div>
        <div class="right_center_content">
            <form id="form1" method="post" action="">
                <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <td valign="top" >
                            <div class="txl_search"></div>
                            <table cellpadding="0" cellspacing="0" border="0" width="100%"  class="sy_table">
                                <tr>
                                    <th colspan="2" >添加友情链接</th>
                                </tr>
                                <tr>
                                    <td width="35%" align="right">链接名称：</td>
                                    <td width="65%"><input type="text" name="linkName"  class="int_text" value="" size="40" /></td>
                                </tr>
                                <tr>
                                    <td width="35%" align="right">链接地址：</td>
                                    <td width="65%"><input type="text" name="linkUrl"  class="int_text" value="http://" size="40" /></td>
                                </tr>
                                <tr>
                                    <td width="35%" align="right">排列顺序：</td>
                                    <td width="65%"><input type="text" name="linkIndex"  class="int_text" size="4" />&nbsp;&nbsp; *请填写1、2、3等阿拉伯数字！</td>
                                </tr>
                                <tr>
                                    <td width="35%" align="right">是否显示：</td>
                                    <td width="65%"><input type="checkbox" name="isEnabled" checked="checked" class="int_text" size="40" /></td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="center" height='30'>
                                        <input type="submit" class="btn_ipt01" name="addLinks" value=" 添加链接 "/>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
</body>
</html>
